#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Solution {
    public:
	int maxProduct(vector<int> &nums)
	{
                int n = nums.size();
                int curmin = nums[0], curmax = nums[0], ans = nums[0];
                for(int i = 1; i < n; i++){
                        int cmin = min({nums[i], curmin * nums[i], curmax * nums[i]});
                        int cmax = max({nums[i], curmin * nums[i], curmax * nums[i]});
                        curmin = cmin;
                        curmax = cmax;
                        ans = max(cmax, ans);
                }
                return ans;
	}
};

int main()
{
        vector<int> nums = {2,3,-2,4};
        cout<<Solution().maxProduct(nums)<<endl;
        return 0;
}